<?php
/**
* Clase base de graficos usando jpgraph
* @file graph.php
* @author DYR Technologies
* @version V 1.0
* @date Wed Oct 03 2007
 *
 *  Part of the CEFIRO dynamic web framework project
 *
 *  Copyright (C) 2007  Dyr technologies http://dyrtech.com.ve
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
* @todo legend
*
*/
include "jpgraph.php";
include "jpgraph_error.php";

$graph_instance = 0;

/**
 * @brief defines para las configuraciones por defecto de los graficos
 */
define('ANCHOXDEF',750);
define('ALTOXDEF',400);
define('TIPO_FUENTE',FF_VERASERIF);
define('TIPO_LETRA',FS_NORMAL);
define('COLORMARGEN','lightsteelblue');
define('COLORFONDO','beige');
define('COLORGRADIENT','white');

class basicGraph{
  private $nombre;
  protected $graph;

  public function basicGraph($nombre = null,
      $ancho = ANCHOXDEF, $alto = ALTOXDEF ){

    /**
     * @brief contador de elementos de grafico instanciados
     */
    global $graph_instance;
    $graph_instance++;
    /**
     * @brief si no tiene nombre le da uno automaticamente segun un contador
     */
    if(isset($nombre)){
      $this->nombre = $nombre;
    } else {
      $this->nombre = "graph_$graph_instance";
    }
    $this->graph = new Graph($ancho,$alto,"auto");
    //$this->graph->img->SetAntiAliasing();
    $this->graph->legend->Pos(0.03,0.5,"right","center");
    $this->graph->legend->SetFont(TIPO_FUENTE, TIPO_LETRA, 8);
  }

  public function titulos($titulo = null, $subtitulo = null,
      $titulox = null, $tituloy = null, $tam_tit = 10, $tam_sub = 9,
      $tipo_fuente = TIPO_FUENTE, $tipo_letra = TIPO_LETRA){
    /**
     * @brief conjunto de bloques de ajuste de titulos del grafico
     */
    if(isset($titulo)){
      $this->graph->title->Set($titulo);
      $this->graph->title->SetFont($tipo_fuente, $tipo_letra, $tam_tit);
    }
    if(isset($subtitulo)){
      $this->graph->subtitle->Set($subtitulo);
      $this->graph->subtitle->SetFont($tipo_fuente, $tipo_letra, $tam_sub);
    }
    if(isset($titulox)){
      $this->graph->xaxis->title->Set($titulox);
      $this->graph->xaxis->title->SetFont($tipo_fuente, $tipo_letra, $tam_sub);
    }
    if(isset($tituloy)){
      $this->graph->yaxis->title->Set($tituloy);
      $this->graph->yaxis->title->SetFont($tipo_fuente, $tipo_letra, $tam_sub);
    }
  }

  /**
  * Permite establecer un estilo para el grafico
  *
  * @param string $colormargen Color del margen
  * @param string $colorfondo Color del fondo del grafico
  * @param boolean $degradado True si el color de fondo es degradado
  */
  public function estilos($colormargen = COLORMARGEN, $colorfondo = COLORFONDO,
    $degradado=true, $sombreado=true){
    if ($sombreado) {
      $this->graph->SetShadow();
    }

    $this->graph->SetMarginColor($colormargen);

    if ($degradado){
      $this->graph->SetBackgroundGradient(
      COLORGRADIENT, $colorfondo, GRAD_HOR, BGRAD_PLOT);
    } else {
      $this->graph->SetColor($colorfondo);
    }
  }

  public function drawGraph($filename = '') {
    $this->graph->Stroke($filename);
  }
}
?>